home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / system / bsvc-1.000 / bsvc-1 / bsvc-1.0.4 / src / Sim68000 / loader / Loader.cxx next >
Encoding:
C/C++ Source or Header  |  1995-07-26  |  2.9 KB  |  121 lines

  1. /////////////////////////////////////////////////////////////////////////////// //
  2. // $Id: Loader.cxx,v 1.1 1994/02/18 20:19:04 bmott Exp $
  3. /////////////////////////////////////////////////////////////////////////////// //
  4. // Loader.cxx
  5. //
  6. // Class to load object files
  7. //
  8. // Sim68000 "Motorola 68000 Simulator"
  9. // Copyright (c) 1993
  10. // By: Bradford W. Mott
  11. // November 5,1993
  12. //
  13. ///////////////////////////////////////////////////////////////////////////////
  14. // $Log: Loader.cxx,v $
  15. // Revision 1.1  1994/02/18  20:19:04  bmott
  16. // Initial revision
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19.  
  20. #include <iostream.h>
  21. #include <fstream.h>
  22. #include "BasicCPU.hxx"
  23. #include "Tools.hxx"
  24. #include "Loader.hxx"
  25.  
  26. ///////////////////////////////////////////////////////////////////////////////
  27. // Load the named file into the address space 
  28. ///////////////////////////////////////////////////////////////////////////////
  29. String Loader::Load(const char* filename, int space)
  30. {
  31.   String error;
  32.  
  33.   // Open the file for reading
  34.   fstream file(filename, ios::in);
  35.  
  36.   // Make sure the file was opened
  37.   if(file.bad())
  38.   {
  39.     error="ERROR: Could not open file!!!";
  40.     return(error);
  41.   }
  42.  
  43.   error=LoadMotorolaSRecord(file,space);
  44.  
  45.   return(error);
  46. }
  47.  
  48. ///////////////////////////////////////////////////////////////////////////////
  49. // Load in a Motorola S-Record file into an address space
  50. ///////////////////////////////////////////////////////////////////////////////
  51. String Loader::LoadMotorolaSRecord(fstream& file,int space)
  52. {
  53.   unsigned long address;
  54.   String line;
  55.   int t,length,byte;
  56.  
  57.   while(!file.eof())
  58.   {
  59.     file >> line;
  60.     if(line[0]!='S')
  61.     {
  62.       return("ERROR: Incorrect file format!!!");
  63.     }
  64.     else if(line[1]=='1')
  65.     {
  66.       line.del(0,2);
  67.       length=StringToInt(line(0,2));
  68.       line.del(0,2);
  69.       address=StringToInt(line(0,4));
  70.       line.del(0,4);
  71.       for(t=0;t<length-3;++t)
  72.       {
  73.         byte=StringToInt(line(0,2));
  74.         line.del(0,2);
  75.         CPU()->address_space[space].Poke(address+t,(unsigned char)byte);
  76.       }
  77.     }
  78.     else if(line[1]=='2')
  79.     {
  80.       line.del(0,2);
  81.       length=StringToInt(line(0,2));
  82.       line.del(0,2);
  83.       address=StringToInt(line(0,6));
  84.       line.del(0,6);
  85.       for(t=0;t<length-4;++t)
  86.       {
  87.         byte=StringToInt(line(0,2));
  88.         line.del(0,2);
  89.         CPU()->address_space[space].Poke(address+t,(unsigned char)byte);
  90.       }
  91.     }
  92.     else if(line[1]=='3')
  93.     {
  94.       line.del(0,2);
  95.       length=StringToInt(line(0,2));
  96.       line.del(0,2);
  97.       address=StringToInt(line(0,8));
  98.       line.del(0,8);
  99.       for(t=0;t<length-5;++t)
  100.       {
  101.         byte=StringToInt(line(0,2));
  102.         line.del(0,2);
  103.         CPU()->address_space[space].Poke(address+t,(unsigned char)byte);
  104.       }
  105.     }
  106.     else if(line[1]=='7')
  107.     {
  108.       break;
  109.     }
  110.     else if(line[1]=='8')
  111.     {
  112.       break;
  113.     }
  114.     else if(line[1]=='9')
  115.     {
  116.       break;
  117.     }
  118.   }
  119.   return("");
  120. }  
  121.